<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		
		<button @click="showVideo()">点击看广告</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {
			setTimeout(() => {
				// init('zgy6g49yinybb56tcw')
				// 创建实例
				this.ad = tt.createRewardedVideoAd({
					adUnitId: 'zgy6g49yinybb56tcw'
				});
				// 监听错误
				this.ad.onError(err => {
					tt.hideLoading();
					switch (err.errCode) {
						case 1004:
							// 无合适的广告
							break;
						default:
						// 更多请参考错误码文档
					}
				});
					 
				// 监听视频播放完成
				this.ad.onClose(data => {
					tt.hideLoading();
					if (data.isEnded) {
						console.log('观看了', data.count, '个视频');
					} else {
						console.log('未观看完视频');
					}
				});
					 
				// 预加载资源
				this.ad.load();
			}, 3000)
		},
		methods: {
			init(id){
				
			},
		
			// 展示激励视频
			showVideo() {
				console.log(1111)
				tt.showLoading();
				this.ad.show();
			},
			haha(e) {
				console.log(e);
			}
	}

	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
